/**
 * 从传入的data中找找个id的所有父节点
 * @param {el, w, h, ox, oy, n, f} data case中的对象与id
 * el 对象
 * w:方块的款
 * h:方块的高
 * ox：每一单元横向便宜
 * oy:每一单元纵向偏移
 * u：单元数
 * f:最大层数
 * n:户数
 */
function CanvasUtils (el, w, h, ox, oy, u, f, n) {
  this.el = el
  this.ctx = el.getContext('2d')
  this.x = 0
  this.y = 0
  this.color = '#FFFFFF'
  this.scaleX = 1
  this.ScaleY = 1
  el.width =
    w * n + (u - 1) * ox < el.parentNode.offsetWidth - 55
      ? el.parentNode.offsetWidth - 55
      : w * n + (u - 1) * ox
  el.height = (h + oy) * f + 80 < 400 ? 400 : (h + oy) * f + 80
}
CanvasUtils.prototype.drawRect = function (
  x,
  y,
  width,
  height,
  offsetX,
  offsetY
) {
  if (!offsetX) offsetX = 0
  if (!offsetY) offsetY = 0
  this.ctx.translate(0, 0)
  this.ctx.strokeStyle = '#666666'
  this.ctx.fillStyle = '#D1EEEE'
  this.ctx.lineWidth = 1
  this.ctx.fillRect(x + offsetX, y + offsetY, width, height)
  this.ctx.strokeRect(x + offsetX, y + offsetY, width, height)
}
CanvasUtils.prototype.drawTitle = function (n, x) {
  this.ctx.font = '30px Microsoft YaHei'
  this.ctx.fillStyle = '#409EFF'
  this.ctx.textAlign = 'center'
  this.ctx.fillText(n + 1 + '单元', x, 50)
}
CanvasUtils.prototype.drawUnite = function (x, y, n, f) {
  this.ctx.font = '20px Microsoft YaHei'
  this.ctx.fillStyle = '#409EFF'
  this.ctx.textAlign = 'center'
  this.ctx.textBaseline = 'middle'
  this.ctx.fillText(n + '0' + f, x, y)
}
CanvasUtils.prototype.clearCanvas = function () {
  this.ctx.clearRect(0, 0, this.el.width, this.el.height)
  this.el.width = 0
  this.el.height = 0
}
module.exports = CanvasUtils
